﻿<Window x:Class="DienLib.PopUp.ContextMenuFormTest"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:system="clr-namespace:System;assembly=mscorlib"
    Title="Window1" Height="300" Width="300">
    <Window.Resources>
        <system:Double x:Key="ImageSize">24</system:Double>
        <!--
        <Style TargetType="{x:Type MenuItem}">
            <Setter Property="Background" Value="#0f3c5a"></Setter>
            <Setter Property="Foreground" Value="White"></Setter>
            <Style.Triggers>
                <Trigger Property="IsHighlighted" Value="True">
                    <Setter Property="Background" Value="Black"></Setter>
                </Trigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground" Value="LightGray"></Setter>
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style TargetType="{x:Type ContextMenu}">
            <Setter Property="OverridesDefaultStyle" Value="True"/>
            <Setter Property="SnapsToDevicePixels" Value="True"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ContextMenu}">-->

        <!--Here is where you change the border thickness to zero on the menu-->
        <!--<Border BorderThickness="0" x:Name="Border"  >
                            <StackPanel ClipToBounds="True" Orientation="Vertical"
                     IsItemsHost="True"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter TargetName="Border" Property="Background" Value="#5082a4" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>-->

        <Style TargetType="{x:Type ContextMenu}">
            <Setter Property="OverridesDefaultStyle" Value="False"/>
            <Setter Property="Padding" Value="0"></Setter>
            <Setter Property="BorderThickness"  Value="2"></Setter>
            <Setter Property="BorderBrush"  Value="Black"></Setter>
        </Style>
        
        <Style TargetType="{x:Type MenuItem}">
            <Setter Property="Background" Value="Crimson"></Setter>
            <!--<Setter Property="Foreground" Value="White"></Setter>-->
            <Setter Property="FontSize" Value="13"></Setter>
            <Setter Property="FontFamily" Value="Verdana"></Setter>
            <Setter Property="Margin" Value="-4,0,0,0"></Setter>
            <Style.Triggers>
                <Trigger Property="IsHighlighted" Value="True">
                    <Setter Property="Background" Value="Black"></Setter>
                    <Setter Property="FontSize" Value="15"></Setter>
                </Trigger>
                <Trigger Property="IsEnabled" Value="False">
                    <Setter Property="Foreground" Value="LightGray"></Setter>
                </Trigger>
            </Style.Triggers>
        </Style>

    </Window.Resources>
    <Grid>
        <Button Margin="82,28,87,184" Content="Right Click Me" Name="but1" Click="but1_Click">
            <Button.ContextMenu >
                <ContextMenu Padding="0" BorderBrush="Black" ContextMenuOpening="ContextMenu_ContextMenuOpening_1">
                    <!-- <MenuItem>
                        <MenuItem.Header>
                            <TextBlock Text="Option 1" 
                                       VerticalAlignment="Center">
                            </TextBlock>
                        </MenuItem.Header>
                        <MenuItem.Icon>
                            <Border Background="LightGray" Name="Wrapper">
                                <Image Source="Cancel.png" 
                                       Width="{StaticResource ImageSize}" 
                                       Height="{StaticResource ImageSize}">
                                </Image>
                            </Border>
                        </MenuItem.Icon>
                    </MenuItem>
                    <MenuItem IsEnabled="False">
                        <MenuItem.Header>
                            <TextBlock Text="Option 2" VerticalAlignment="Center"></TextBlock>
                        </MenuItem.Header>
                        <MenuItem.Icon>
                            <Border Background="LightGray">
                                <Image Source="ValidGreen.png" 
                                       Width="{StaticResource ImageSize}" 
                                       Height="{StaticResource ImageSize}"></Image>
                            </Border>
                        </MenuItem.Icon>
                    </MenuItem>-->

                    <MenuItem x:Name="mnItem1" Background="#FF8C16C1" Margin="-4,0,0,0" Foreground="#FFE15151" ContextMenuOpening="mnItem1_ContextMenuOpening" ContextMenuClosing="mnItem1_ContextMenuClosing" Click="mnItem1_Click">
                        <MenuItem.Header>
                            <Border Background="Green">
                                <TextBlock x:Name="tbItem1" Text="Option 3" VerticalAlignment="Center"></TextBlock>
                            </Border>
                            
                        </MenuItem.Header>
                        <MenuItem.Icon>
                            <Border x:Name="bdItem1" Background="Red">
                                <Image Source="Refresh.png" 
                                       Width="{StaticResource ImageSize}" 
                                       Height="{StaticResource ImageSize}"></Image>
                            </Border>
                        </MenuItem.Icon>



                        <MenuItem x:Name="mnItem11" ContextMenuOpening="mnItem11_ContextMenuOpening">
                            <MenuItem.Header>
                                <TextBlock x:Name="tbItem11" Text="Option 3.3" VerticalAlignment="Center" Background="Yellow"></TextBlock>
                            </MenuItem.Header>
                            <MenuItem.Icon>
                                <Border x:Name="bdItem11" Background="Red">
                                    <Image Source="Refresh.png" 
                                       Width="{StaticResource ImageSize}" 
                                       Height="{StaticResource ImageSize}"></Image>
                                </Border>
                            </MenuItem.Icon>
                        </MenuItem>




                        <MenuItem x:Name="mnItem12">
                            <MenuItem.Header>
                                <TextBlock x:Name="tbItem12" Text="Option 3.2" VerticalAlignment="Center" HorizontalAlignment="Center" Background="Yellow"></TextBlock>
                            </MenuItem.Header>
                            <MenuItem.Icon>
                                <Border x:Name="bdItem12" Background="Red">
                                    <Image Source="Refresh.png" 
                                       Width="{StaticResource ImageSize}" 
                                       Height="{StaticResource ImageSize}"></Image>
                                </Border>
                            </MenuItem.Icon>
                        </MenuItem>



                    </MenuItem>
                    <MenuItem x:Name="mnItem2" Click="mnItem2_Click" ContextMenuOpening="mnItem2_ContextMenuOpening">
                        <MenuItem.Header>
                            <TextBlock x:Name="tbItem2" Text="dd 4" VerticalAlignment="Center" Background="Yellow"></TextBlock>
                        </MenuItem.Header>
                        <MenuItem.Icon>
                            <Border x:Name="bdItem2" Background="Red">
                                <Image Source="PlayGreen.png" 
                                       Width="{StaticResource ImageSize}" 
                                       Height="{StaticResource ImageSize}"></Image>
                            </Border>
                        </MenuItem.Icon>

                        <MenuItem IsEnabled="False">
                            <MenuItem.Header>
                                <TextBlock Text="Option 2" VerticalAlignment="Center"></TextBlock>
                            </MenuItem.Header>
                            <MenuItem.Icon>
                                <Border Background="LightGray">
                                    <Image Source="ValidGreen.png" 
                                       Width="{StaticResource ImageSize}" 
                                       Height="{StaticResource ImageSize}"></Image>
                                </Border>
                            </MenuItem.Icon>
                        </MenuItem>
                    </MenuItem>
                </ContextMenu>
            </Button.ContextMenu>
        </Button>
    </Grid>
</Window>